package cn.jy.machine.common;

import lombok.Data;

@Data
public class Result {
    private int code;
    private String msg;
    private Long total;
    private Object data;

    public Result(){

    }

    private static Result result(int code, String msg, Long total, Object data) {
        Result res = new Result();
        res.setCode(code);
        res.setData(data);
        res.setTotal(total);
        res.setMsg(msg);
        return res;
    }

    private static Result result(StatusCode statusCode, Long total, Object data) {
        return result(statusCode.getCode(), statusCode.getMsg(), total, data);
    }

    private static Result result(StatusCode statusCode) {
        return result(statusCode, null, null);
    }

    // 修改 success 方法，使其使用 result 方法
    private static Result success(Long total, Object data) {
        return result(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMsg(), total, data);
    }

    public static Result fail() {
        return result(StatusCode.FAIL);
    }

    public static Result fail(StatusCode statusCode) {
        return result(statusCode);
    }

    public static Result success() {
        return result(StatusCode.SUCCESS);
    }

    public static Result success(Object data) {
        return success(0L, data);
    }

    public static Result publicSuccess(Long total, Object data) {
        return success(total, data);
    }
}
